﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NoORM.Core;
using NoORM.Core.Contract;
using NoORM.Core.DbAcceess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Restsql.Api.Controllers
{
    /// <summary>
    /// 获取数据库配置的名称集合
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class DbController : ControllerBase
    {
        /// <summary>
        /// 数据库连接字符串配置
        /// </summary>
        private readonly Dictionary<string, ConnectionStringConfig> configs;

        public DbController(IOptions<Dictionary<string, ConnectionStringConfig>> configsOption)
        {
            this.configs = configsOption.Value;
        }

        [HttpGet]
        public async Task<JsonResult> Get()
        {
            ApiData<List<string>> api = new ApiData<List<string>>();
            api.ServerReceiveTime = DateTime.Now;
            api.Success = true;
            api.Data = this.configs.Keys.ToList();
            api.ServerSendTime = DateTime.Now;
            return new JsonResult(api);
        }
    }
}
